package com.quarantine.web;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.Action;
public class FileDownloadAction implements Action {
    private String inputPath;
    private String filename;
    private String uploadname;
    public void setInputPath(String value) {
        inputPath = value;
    }
    //获取下载的文件
    public InputStream getInputStream() throws Exception {
    System.out.println("********************************************************8");
      //inputPath="/images/struts.gif";
    	System.out.println(filename);
    	inputPath="/upload/"+filename;
    	System.out.println(inputPath);
    	System.out.println(uploadname);
		setFilename(uploadname);
		System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
	  	System.out.println(filename);
    System.out.println("---------"+ServletActionContext.getServletContext().getResourceAsStream(inputPath)); 
        
    	return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
    }
    public String getInputPath() {
		return inputPath;
	}
	public String execute() throws Exception {
		
        return SUCCESS;
    }
	public String getUploadname() {
		return uploadname;
	}
	public void setUploadname(String uploadname) {

		this.uploadname = uploadname;
	}
	public String getFilename() throws UnsupportedEncodingException {
		System.out.println(filename);
		System.out.println("_______________________________________");
        filename = URLEncoder.encode(filename, "ISO8859-1");
		System.out.println(filename);
		return filename;
	}
	public void setFilename(String filename) {
		this.filename = filename;
	}
}